package com.zzc.service.impl;

import com.zzc.domain.Staff;
import com.zzc.repository.StaffRep;
import com.zzc.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StaffServiceImpl implements StaffService {

    @Autowired
    StaffRep staffRep;

    @Override
    public List<Staff> getAllStaff() {
        return staffRep.findAll();
    }

    @Override
    public void addStaff(Staff staff) {
        staffRep.save(staff);
    }

    @Override
    public Staff findOneById(int staffId) {
        return staffRep.findByStaffId(staffId);
    }

    @Override
    public void editStaff(Staff staff) {
        staffRep.deleteByStaffId(staff.getStaffId());
        staffRep.save(staff);
    }

    @Override
    public int getStaffCount() {
        return (int) staffRep.count();
    }
}
